package top.kaoshanji.p2chapters.mapper;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import top.kaoshanji.p2chapters.model.Country;

import java.util.List;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/13 9:26
 */
public class CountryMapperTest extends BaseMapperTest {

    /**
     * 代码清单test-p3ch17b-29页a：测试重写查询所有的国家编码
     */
    @Test
    public void testSelectAll() {
        SqlSession sqlSession = getSqlSession();
        try {
            // 因为在全局selectAll不再是唯一了，就需要加上命名空间
            List<Country> countryList = sqlSession.selectList("top.kaoshanji.p2chapters.mapper.CountryMapper.selectAll");
            printCountryList(countryList);
        } finally {
            sqlSession.close();
        }
    }

    private void printCountryList(List<Country> countryList) {
        for (Country country : countryList) {
            System.out.printf("%-4d%4s%4s\n", country.getId(), country.getCountryname(), country.getCountrycode());
        }
    }


}
